﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class TransportCompanyAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable dt = new DataLib.BLL.Cumtomer().GetList("").Tables[0];
                ddlcustomername.DataSource = dt;
                ddlcustomername.DataTextField = "companyname";
                ddlcustomername.DataValueField = "id";
                ddlcustomername.DataBind();
                ddlcustomername.Items.Insert(0, new ListItem("无", "0"));
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtcompanyname.Text.Trim().Length == 0)
            {
                strErr += "运输公司名称不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string customerid = "0";
            if (ddlcustomername.SelectedValue != "" && ddlcustomername.SelectedValue != "0")
                customerid = ddlcustomername.SelectedValue;
            
            string companyname = this.txtcompanyname.Text;
            string linkman = this.txtlinkman.Text;
            string phone = this.txtphone.Text;

            DataLib.Model.TransportCompany model = new DataLib.Model.TransportCompany();
            model.customerid = int.Parse(customerid);
            model.companyname = companyname;
            model.linkman = linkman;
            model.phone = phone;

            DataLib.BLL.TransportCompany bll = new DataLib.BLL.TransportCompany();
            bll.Add(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "TransportCompanyAdd.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("TransportCompanyList.aspx");
        }
    }
}
